import React, { lazy, Suspense } from 'react';
import { Navigate } from 'react-router-dom';
import Home from '@/pages/home/index.jsx';
import Login from '@/pages/Login.jsx';
import ProtectedRoute from '@/components/ProtectedRoute.jsx';

// 使用 React.lazy 懒加载 About 组件
const Chat = lazy(() => import('@/pages/chat'));

const routes = [
  {
    path: '/',
    element: <Navigate to="/home" />,
  },
  {
    path: '/home',
    element: <ProtectedRoute><Home /></ProtectedRoute>,
  },
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/chat',
    element: <Suspense fallback={<div>Loading...</div>}>
      <Chat />
    </Suspense>
  },
  {
    path: '*',
    element: <Navigate to="/home" />,
  },
];

export default routes;